<template>
	<eui-page-frame topHeight="255">
		<template #top>
			<view class="content-img">
				<eui-navbar ref="EuiNavBar" title="选择费用方案" color="#000000" backgroundColor="#FFFFFF">
				</eui-navbar>
				<view class="top-view">
					<eui-search-bar ref="RdsSearchBar" v-model="searchText" placeholder="请输入费用编号" leftIcon="icon-sousuo"
						@confirm="searchConfirm" @leftIconClick="leftIconClick" radius="30">
					</eui-search-bar>
				</view>
			</view>
		</template>
		<eui-page-content>
			<view class="footer-view">
				<scroll-view :scroll-top="0" scroll-y="true" style="height: auto;" @scrolltolower="loadMore">
					<eui-base-card v-for="(item, index) in dataList" :key="index" @click="templateClick(item)">
						<eui-detail-show :items="Items" v-model="dataList[index]" size="small"></eui-detail-show>
					</eui-base-card>
				</scroll-view>
			</view>
		</eui-page-content>
	</eui-page-frame>
</template>

<script setup type="ts">
	import { ref, reactive, onMounted } from 'vue';
	import {useMainStore} from "@/store/modules/store";
	import {useLoginStore} from "@/store/modules/useLoginStore";
	import { validateStores } from '@/hooks/useValidateMethod';
	import dateRangUtil from '../../../../common/dateRangUtil';
	import { getRelatedName, getDictName,getDictSelectList, getDictSelect } from '../../components/RelatedName.js';
	import Enjoy from "@/common/enjoy";
	import {onLoad} from "@dcloudio/uni-app";
	import { init } from '@/hooks/init';
	import useService from '@/hooks/useService';
	const service = useService({ prefix: "bcApi" });
	
	const mainStore = useMainStore();
	const LoginStore = useLoginStore();
	const EuiNavBar = ref(null);
	const RdsSearchBar = ref(null);
	const searchText = ref('');
	const sUserStore = ref('');
	const sUserStoreName = ref('');
	const sUser = ref('');
	const dataList = ref([]);
	const c_store_id = ref('');
	const c_gcode = ref('');
	const CurrentPage = ref(1);  //第几页
	const PageSize = ref(10);  //每页10条
	const RowsCount = ref(0);  //总条数
	const PageCount = ref(1);  //总页数
	const { loginInfo } = mainStore;
	const Items = [
		{
			label: "编码",
			prop: "c_no",
			type: "text",
			colSpan: 24,
			element: {
			},
		},
		{
			label: "名称",
			prop: "c_name",
			type: "text",
			colSpan: 12,
			element: {
			},
		},
		{
			label: "金额",
			prop: "c_amount",
			type: "text",
			colSpan: 12,
			element: {
				precision: 2
			},
		},
		{
			label: "说明",
			prop: "c_desc",
			type: "text",
			colSpan: 24,
			element: {
				
			},
		}
	]
	
	onLoad(async () => {
	  await getData();
	})
	

	const templateClick = (e) => {
		let pages = getCurrentPages(); //获取所有页面栈实例列表
		let prevPage = pages[pages.length - 2]; //上一页页面实例
		prevPage.$vm.$.exposed.SelectionChanged({
                type: 'c_fee_id',
                c_fee_id: e.c_no,
                c_amount: e.c_amount,
            }); //执行函数也是同理
		uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
			delta: 1
		});
	};
	const leftIconClick = async()=>{
		await getData();
	}
	const searchConfirm = async (e) => {
	  if (!e) {
	    return;
	  }
	  searchText.value = e.value;
	  await getData();
	}
	// 查询数据列表
	const getData = async(e) =>{
		if (!e) {
			CurrentPage.value = 1;
			dataList.value = [];
		}
		uni.showLoading({ title: "正在加载...", mask: true })
	  const req = {
					WhereList: [
						{
							c_col: "c_status",
							c_oper: "相似",
							c_value: '1',
							c_logic: "而且",
						}
					]
				};
	
		if (searchText.value) {
			req.WhereList.push({
				c_col: "c_no",
				c_oper: "等于",
				c_value: searchText.value,
				c_logic: "而且",
			});
		}
		const result = await service.request('采购费用方案维护', 'EnjoyQueryList', req,'801');
		uni.hideLoading();
		CurrentPage.value = result.CurrentPage; //第几页
		PageSize.value = result.PageSize; //每页10条
		RowsCount.value = result.RowsCount; //总条数
		PageCount.value = result.PageCount; //总页数 
		const _data =  result.ReturnObject.map(x=>{
				return {
					...x,
					c_out_store_name:x.c_out_store_id?'['+x.c_out_store_id+']'+getRelatedName('rdsStores', x.c_out_store_id):'',
					c_out_wno_name:x.c_out_wno?'['+x.c_out_wno+']'+getRelatedName('rdsWnos', x.c_out_wno):''
				}
			});
		if (result.CurrentPage == 1) {
			dataList.value = _data;
		} else {
			dataList.value = dataList.value.concat(_data);
		}
	}
	const loadMore = async() => {
		if (CurrentPage.value < PageCount.value) {
			CurrentPage.value = CurrentPage.value + 1;
			await getData(true);
		}
	}
</script>
<style lang="scss" scoped>
	@import '../../../../main.scss';

	.content {
		display: flex;
		flex: 1;
		flex-direction: column;
		background-color: #F2F2F2;
		padding: 0px !important
	}

	.content-img {
		background-color: #FFFFFF;
		background-size: 100% 176rpx;
		background-repeat: no-repeat;
		width: 100%;
	}

	.navigation {
		flex: 0 0 auto;
		margin-bottom: 5px;
	}

	.footer-view {
		width: 100%;
		flex: 1;
	}

	.bt-button {
		background-color: #FFFFFF;
		padding: 10rpx 0rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
	}
</style>